class Solution {
public:
    int canCompleteCircuit(vector<int>& gas, vector<int>& cost)
    {
        for (int i = 0; i < cost.size(); i++)
        {
            int rest = 0;
            int step;
            for (step = 0; step < cost.size(); step++)
            {
                int index = (i + step) % cost.size();
                rest = rest + gas[index] - cost[index];
                if (rest < 0) break;
            }
            if (rest >= 0)return i;
            i = i + step;
        }
        return -1;
    }
};